<template>
  <div id="AsnDetailList">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="selectData"
                  @backList="backList"
                  @del="del"
                  @newCreate="newCreate"></v-tableTitle>
    <div class="detail">

      <component :data="{detailData,argument}"
                 :is="currentComponent"></component>
    </div>
  </div>

</template>

<script>
import tableTitle from "commons/TableTitle";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "DetailList",
  mixins: [baseMixin],
  data () {
    return {
      newFlag: false,
      argument: {},
      detailData: {},
      selectData: [],

      detailNav: "1",
      componentConfig: [
        {
          name: "Table",
          label: "table",
          component: () => import('./page/Table.vue')
        },
        {
          name: "GatherDetailDetail",
          label: this.$t('out.GatherDetailDetail'),
          component: () => import('./page/GatherDetailDetail.vue')
        },
      ]
    }
  },
  computed: {
    btnConfig () {
      if (this.detailNav == 1) {
        return [
          { label: this.$t('common.create'), certigier: this.newStatus, invalid: "newCreate" },
          { label: this.$t('common.delete'), certigier: this.deletedetailStatus, disabled: true, invalid: "del" },
        ]
      } else if (this.$store.state.newFlag) {
        return []
      } else {
        return [
          { label: this.$t('common.return'), invalid: "backList" },
        ]
      }
    },
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    //删除数据
    async del (data) {
      try {
        let res = await this.$api.post(`/deleteGatherdetail`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page')
          this.$children[1].getTableData(1, {})
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.$children[1].$refs.table.delSelectData(data);
      }
    },
    //选中的数据
    setSelectData (data) {
      this.selectData = data;
    },
    //返回试图
    backList () {
      this.detailNav = "1";
      this.$store.commit("setDetailsNew", false);
    },
    //新建
    async newCreate () {
      try {
        let res = await this.$api.get(`/queryGatherMaxLine/${this.argument.gatherkey}`);
          this.detailData = {
            gatherlinenumber: res.data.seq,
            orderkey: "",
            whseid: res.data.whseid,
            gatherkey: this.argument.gatherkey,
          };
          this.detailNav = "2";
        
      } catch (e) {
        this.$message.error(e);
      }
    },
  },
  mounted () {
    this.newFlag = this.$store.state.newFlag;
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.argument = data.routeData;
      this.detailData = data.detailList;
      this.detailNav = data.detailListNav;
    } else if (this.newFlag) {
      this.detailData = {
        gatherlinenumber: "",
        orderkey: "",
        wavekey: '',
        gatherkey: this.$store.state.routeId,
      };
      this.detailNav = "2";
    } else {
      this.argument = this.$store.state.routeData;
    }

  },
  components: {
    "v-tableTitle": tableTitle,
    "v-navMenu": navMenu,
  },
  watch: {
    selectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deletedetailStatus = false;
        } else {
          this.deletedetailStatus = true;
        }
      }
    }
  }
}
</script>

<style>
</style>
